/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

import com.click.app.Functions;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author ariel
 */
@Entity
@Table(name = "cut_details")
public class CutDetail extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private Long id; // identifier
    private Integer quantity; // quantity of cutters
    private Integer quantityGet; // quantity gets
    
    private CutProcess cutProcess;
    private PantDesign pantDesign;
    private Double priceXclothes;
    private Integer quantityFail;
    private Double priceXclotheFail;
    private Double totalAmountClothes;
    private Double totalAmountFailClothes;
    private Integer quantityRealClothes;
    private Integer quantityRealClothesCurrent; // quantity gets current
    private Double totalAmount;
    private Double currentAmount;

    private List<PantDetailCutDetail> pantDetailCutDetails = new ArrayList<PantDetailCutDetail>();
    private boolean modify;
    private Long idTemp;
    public CutDetail(){ }
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_cut_detail", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "modify")
    public boolean isModify() {
        return modify;
    }

    public void setModify(boolean modify) {
        this.modify = modify;
    }

    @Column(name = "quantity")
    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    @Column(name = "quantity_real_clothes_current")
    public Integer getQuantityRealClothesCurrent() {
        return quantityRealClothesCurrent;
    }

    public void setQuantityRealClothesCurrent(Integer quantityRealClothesCurrent) {
        this.quantityRealClothesCurrent = quantityRealClothesCurrent;
    }

    @Column(name = "quantity_real_clothes")
    public Integer getQuantityRealClothes() {
        return quantityRealClothes;
    }

    public void setQuantityRealClothes(Integer quantityRealClothes) {
        this.quantityRealClothes = quantityRealClothes;
    }

    @Column(name = "total_amount_clothes")
    public Double getTotalAmountClothes() {
        return Functions.getDouble3Decimal(totalAmountClothes);
    }

    public void setTotalAmountClothes(Double totalAmountClothes) {
        this.totalAmountClothes = Functions.getDouble3Decimal(totalAmountClothes);
    }

    @Column(name = "total_amount_fail_clothes")
    public Double getTotalAmountFailClothes() {
        return Functions.getDouble3Decimal(totalAmountFailClothes);
    }

    public void setTotalAmountFailClothes(Double totalAmountFailClothes) {
        this.totalAmountFailClothes = Functions.getDouble3Decimal(totalAmountFailClothes);
    }

    @Column(name = "quantity_get")
    public Integer getQuantityGet() {
        return quantityGet;
    }

    public void setQuantityGet(Integer quantityGet) {
        this.quantityGet = quantityGet;
    }

    @JoinColumn(name = "id_pant_design", referencedColumnName = "id_pant_design")
    @ManyToOne(optional = false)
    public PantDesign getPantDesign() {
        return pantDesign;
    }

    public void setPantDesign(PantDesign pantDesign) {
        this.pantDesign = pantDesign;
    }

    @JoinColumn(name = "id_cut_process", referencedColumnName = "id_cut_process")
    @ManyToOne(optional = false)
    public CutProcess getCutProcess() {
        return cutProcess;
    }

    public void setCutProcess(CutProcess cutProcess) {
        this.cutProcess = cutProcess;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cutDetail")
    public List<PantDetailCutDetail> getPantDetailCutDetails() {
        return pantDetailCutDetails;
    }

    public void setPantDetailCutDetails(List<PantDetailCutDetail> pantDetailCutDetails) {
        this.pantDetailCutDetails = pantDetailCutDetails;
    }

    @Column(name = "current_amount")
    public Double getCurrentAmount() {
        return Functions.getDouble3Decimal(currentAmount);
    }

    public void setCurrentAmount(Double currentAmount) {
        this.currentAmount = Functions.getDouble3Decimal(currentAmount);
    }

    @Column(name = "prices_x_clothes")
    public Double getPriceXclothes() {
        return Functions.getDouble3Decimal(priceXclothes);
    }

    public void setPriceXclothes(Double priceXclothes) {
        this.priceXclothes = Functions.getDouble3Decimal(priceXclothes);
    }

    @Column(name = "price_x_clothe_fail")
    public Double getPriceXclotheFail() {
        return Functions.getDouble3Decimal(priceXclotheFail);
    }

    public void setPriceXclotheFail(Double priceXclotheFail) {
        this.priceXclotheFail = Functions.getDouble3Decimal(priceXclotheFail);
    }

    @Column(name = "quantity_fail")
    public Integer getQuantityFail() {
        return quantityFail;
    }

    public void setQuantityFail(Integer quantityFail) {
        this.quantityFail = quantityFail;
    }

    @Column(name = "total_amount")
    public Double getTotalAmount() {
        return Functions.getDouble3Decimal(totalAmount);
    }

    public void setTotalAmount(Double totalAmount) {
        this.totalAmount = Functions.getDouble3Decimal(totalAmount);
    }

    @Transient
    public String getIdentifier(){
        return pantDesign.getModel().getDatas() + ", " + pantDesign.getModelSize().getValueSize() + ", " + cutProcess.getEndDate();
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CutDetail)) {
            return false;
        }
        CutDetail other = (CutDetail) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return new ToStringBuilder( this, ToStringStyle.SIMPLE_STYLE).append(this.getId())
                                  .append(this.quantity).append(this.quantityGet).append(this.priceXclothes)
                                  .append(this.quantityFail).append(this.priceXclotheFail).append(this.totalAmount)
                                  .append(this.currentAmount)
                                  .append(this.idTemp)
                                  .toString();
        
    }
    
    @Transient
    public Long getIdTemp() {
        return idTemp;
    }

    public void setIdTemp(Long idTemp) {
        this.idTemp = idTemp;
    }

}
